package com.vone.util;
import java.awt.Image;
import java.io.File;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import javax.swing.ImageIcon;

/**
 * 获取图片图标工具
 * @author wd
 *
 */
public class ImageUtil {

	//图片路径
	private static String imagePath = "/image/";
	
	//系统LOGO
	private static Image logo = null;
	//行李管理图标
	private static Image baggageManag_logo = null;
	//报表图标
	private static Image reportForm_logo = null;
	
	//单选框选中与未选中图标
	private static ImageIcon radioUnselectedIcon = null;
	private static ImageIcon radioSelectedIcon = null;
	
	//复选框选中与未选中图标
	private static ImageIcon checkBoxUnchecked = null;
	private static ImageIcon checkBoxSelected = null;
	private static ImageIcon btnComboBoxIcon=null;
	
	/**
	 * logo图片
	 * @return
	 */
	public static Image getLogo() {
		if (logo == null)
			try {
				logo = ImageIO.read(ImageUtil.class.getResource(imagePath + "logo.png"));
			} catch (Exception e) {
				e.printStackTrace();
			}
		return logo;
	}
	
	/**
	 * 行李管理图标
	 * @return
	 */
	public static Image getBaggageManag_logo() {
		if (baggageManag_logo == null)
			try {
				baggageManag_logo = ImageIO.read(ImageUtil.class.getResource(imagePath + "baggageManag_logo.png"));
			} catch (Exception e) {
				e.printStackTrace();
			}
		return baggageManag_logo;
	}
	
	/**
	 * 报表图标
	 * @return
	 */
	public static Image getReportForm_logo() {
		if (reportForm_logo == null)
			try {
				reportForm_logo = ImageIO.read(ImageUtil.class.getResource(imagePath + "reportForm_logo.png"));
			} catch (Exception e) {
				e.printStackTrace();
			}
		return reportForm_logo;
	}
	
	/**
	 * 判断文件是否是图片
	 * 
	 * @param file
	 * @return
	 */
	public static boolean isImage(File file) {
		boolean flag = false;
		try {
			ImageInputStream is = ImageIO.createImageInputStream(file);
			if (null == is) {
				return flag;
			}
			is.close();
			flag = true;
		} catch (Exception e) {
		}
		return flag;
	}
	
	/**
	 * 获取单选框未选中的图标
	 * 
	 * @return
	 */
	public static ImageIcon getRadioUnselectedIcon() {
		if (radioUnselectedIcon == null) {
			radioUnselectedIcon = new ImageIcon(ImageUtil.class.getResource(imagePath +"radioUnselected.png"));
		}
		return radioUnselectedIcon;
	}

	/**
	 * 获取单选框选中的图标
	 * 
	 * @return
	 */
	public static ImageIcon getRadioSelectedIcon() {
		if (radioSelectedIcon == null) {
			radioSelectedIcon = new ImageIcon(ImageUtil.class.getResource(imagePath +"radioSelected.png"));
		}
		return radioSelectedIcon;
	}
	
	/**
	 * 获取复选框未选中的图标
	 * 
	 * @return
	 */
	public static ImageIcon getCheckBoxUnselected() {
		if (checkBoxUnchecked == null)
			checkBoxUnchecked = new ImageIcon(ImageUtil.class.getResource(imagePath+"checkBoxUnselected.png"));
		return checkBoxUnchecked;
	}

	/**
	 * 获取复选框选中的图标
	 * 
	 * @return
	 */
	public static ImageIcon getCheckBoxSelected() {
		if (checkBoxSelected == null)
			checkBoxSelected = new ImageIcon(ImageUtil.class.getResource(imagePath+"checkBoxSelected.png"));
		return checkBoxSelected;
	}
	
	public static ImageIcon getBtnComboBoxIcon() {
		if(btnComboBoxIcon==null)
			btnComboBoxIcon=new ImageIcon(ImageUtil.class.getResource(imagePath+"comboBoxDown.png"));
		return btnComboBoxIcon;
	}
}
